package bstsetcode.stanforduniversity18;



/**
 * @author noob
 * @version 1.0
 * @date 2021/3/15 16:45
 * 问题1：计算链表的节点个数
 *
 * 需求：你写一个代码，统计列表中某个数的个数
 */
public class _01_Count {



    private int count(ListNode head, int e) {
        int count = 0;
        ListNode cur = head;
        while (cur != null){
            if(cur.val == e ){
                count++;
            }
            cur = cur.next;
        }
        return count;
    }



    public static void main(String[] args) {
//        int[] nums = {1,2,6,3,4,5,6};
        int[] nums = {1,2,6,3,4,5,6,2,3,4,5,6};
        ListNode head = new ListNode(nums);
        int count = new _01_Count().count(head,2);
        System.out.println(count);

    }


}
